using System;
using Neuparts.Shipping.Entities;
using Neuparts.Shipping.Managers;
using Neuparts.Shipping.ServiceInterface.DataContracts;
using Neuparts.Shipping.Tests.TestHelpers;

namespace Neuparts.Shipping.Client
{
    public class Program
    {
        static void Main(string[] args)
        {
            using (InventoryClient client = new InventoryClient())
            {
                InventoryItem item = CreateThreeItemsOfInventory();

                InventoryItemMessage itemMessage = CreateInventoryItemMessage(item);

                Console.WriteLine("The inventory count is " + client.GetCount(itemMessage));
                Console.ReadLine();
            }
        }

        private static InventoryItemMessage CreateInventoryItemMessage(InventoryItem item) {
            InventoryItemMessage itemMessage = new InventoryItemMessage();
            itemMessage._barcode = item.Barcode;
            itemMessage._name = item.Name;
            itemMessage._receivedDate= item.ReceivedDate;
            itemMessage._sku = item.Sku;
            itemMessage._supplierId = item.SupplierId;
            return itemMessage;
        }

        private static InventoryItem CreateThreeItemsOfInventory() {
            InventoryItem item = EntityGenerator.GenerateInventoryItem();
            InventoryItem item2 = EntityGenerator.GenerateInventoryItem();
            InventoryItem item3 = EntityGenerator.GenerateInventoryItem();

            int newSku = (int)DateTime.Now.Ticks;
            item.Sku = newSku;
            item2.Sku = newSku;
            item3.Sku = newSku;

            InventoryManager.Add(item);
            InventoryManager.Add(item2);
            InventoryManager.Add(item3);
            return item;
        }

        public static InventoryItem GenerateInventoryItem()
        {
            InventoryItem item = new InventoryItem();
            item.Barcode = Guid.NewGuid();
            item.Name = "Widget";
            item.Sku = 12345;
            item.ReceivedDate = DateTime.Now;
            item.SupplierId = 98765;
            return item;
        }
    }
}
